package com.suzj.extraenchantments.event;

import com.suzj.extraenchantments.ExtraEnchantments;
import com.suzj.extraenchantments.enchant.EnchantRegistry;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.UUID;

@Mod.EventBusSubscriber(modid = ExtraEnchantments.MODID)

public class ExtraArmorEnchantmentListener {
    private static final UUID REACH_UUID = UUID.fromString("00d4860f-b487-4402-b424-373a52566330");
    private static final String REACH_STRING = "extraenchantments:base_reach";

    @SubscribeEvent
    public static void onLivingEquipmentChange(LivingEquipmentChangeEvent event) {
        var slotType = event.getSlot();
        if (slotType.getType() == EquipmentSlot.Type.ARMOR) {
            int extraArmor = EnchantmentHelper.getItemEnchantmentLevel(EnchantRegistry.insight.get(), event.getEntity().getItemBySlot(slotType)) * 5;
            if (extraArmor > 0) {
                event.getEntity().getAttribute(Attributes.ARMOR).addPermanentModifier(new AttributeModifier(UUID.fromString("d710e94f-86ee-45a9-b0a1-8dab44137db0"), "Extra Armor", extraArmor, AttributeModifier.Operation.ADDITION));
            } else {
                event.getEntity().getAttribute(Attributes.ARMOR).removeModifier(UUID.fromString("d710e94f-86ee-45a9-b0a1-8dab44137db0"));
            }
        }
    }

//    public static void updateBaseReachModifier(Player player, boolean creative) {
//        ModifiableAttributeInstance attribute = player.getAttribute(ForgeMod.REACH_DISTANCE.get());
//        if (attribute != null) {
//            attribute.removeModifier(REACH_UUID);
//            attribute.addPermanentModifier(new AttributeModifier(REACH_UUID, REACH_STRING, 10.0d, AttributeModifier.Operation.ADDITION));
//        }
//    }
}